home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / util / moni / Scout-src.lha / source / objects / scout_allocations.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-09-17  |  10.7 KB  |  305 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28. #include "system_headers.h"
  29.  
  30. struct AllocationsCallbackUserData {
  31.     APTR ud_CIAAUsers;
  32.     APTR ud_CIABUsers;
  33.     APTR ud_PortsUsers;
  34. };
  35.  
  36. static UBYTE alcnonalc[] = "<free>";
  37. static UBYTE alcunknown[] = "<allocated>";
  38. static UBYTE alcnotavail[] = "<not available>";
  39.  
  40. static ULONG __asm __saveds __interrupt DummyIntFunc( void )
  41. {
  42.     return 0;
  43. }
  44.  
  45. static UBYTE *AlcMiscUser( ULONG unit )
  46. {
  47.     struct Library *MiscBase;
  48.  
  49.     if (MiscBase = OpenResource(MISCNAME)) {
  50.         UBYTE *name;
  51.  
  52.         if (name = AllocMiscResource(unit, "Scout")) {
  53.             return name;
  54.         } else {
  55.             FreeMiscResource(unit);
  56.             return alcnonalc;
  57.         }
  58.     } else {
  59.         return alcnotavail;
  60.     }
  61. }
  62.  
  63. static UBYTE *AlcCIAUser( UBYTE *res,
  64.                           WORD unit )
  65. {
  66.     struct Library *CiaBase;
  67.  
  68.     if (CiaBase = OpenResource(res)) {
  69.         struct Interrupt dummyInt, *intr;
  70.  
  71.         memset(&dummyInt, 0x00, sizeof(struct Interrupt));
  72.         dummyInt.is_Node.ln_Type = NT_INTERRUPT;
  73.         dummyInt.is_Node.ln_Pri = -127;
  74.         dummyInt.is_Node.ln_Name = "« Scout's Dummy Int »";
  75.         dummyInt.is_Code = (void (*)())DummyIntFunc;
  76.  
  77.         Disable();
  78.         if ((intr = AddICRVector(CiaBase, unit, &dummyInt)) == NULL) RemICRVector(CiaBase, unit, &dummyInt);
  79.         Enable();
  80.  
  81.         if (intr) {
  82.             return (intr->is_Node.ln_Name) ? (UBYTE *)intr->is_Node.ln_Name : alcunknown;
  83.         } else {
  84.             return alcnonalc;
  85.         }
  86.     } else {
  87.         return alcnotavail;
  88.     }
  89. }
  90.  
  91. static void ReceiveList( void (* callback)( struct AllocationEntry *ae, void *userData ),
  92.                          void *userData )
  93. {
  94.     struct AllocationEntry *ae;
  95.  
  96.     if (ae = tbAllocVecPooled(globalPool, sizeof(struct AllocationEntry))) {
  97.         if (SendDaemon("GetAlcList")) {
  98.             while (ReceiveDecodedEntry((UBYTE *)ae, sizeof(struct AllocationEntry))) {
  99.                 callback(ae, userData);
  100.             }
  101.         }
  102.  
  103.         tbFreeVecPooled(globalPool, ae);
  104.     }
  105. }
  106.  
  107. static void IterateList( void (* callback)( struct AllocationEntry *ae, void *userData ),
  108.                          void *userData )
  109. {
  110.     struct AllocationEntry *ae;
  111.  
  112.     if (ae = tbAllocVecPooled(globalPool, sizeof(struct AllocationEntry))) {
  113.         ULONG i;
  114.  
  115.         Forbid();
  116.  
  117.         for (i = 0; i < 5; i++) stccpy(ae->ae_CIAAUsers[i], AlcCIAUser(CIAANAME, i), sizeof(ae->ae_CIAAUsers[i]));
  118.         for (i = 0; i < 5; i++) stccpy(ae->ae_CIABUsers[i], AlcCIAUser(CIABNAME, i), sizeof(ae->ae_CIABUsers[i]));
  119.         stccpy(ae->ae_PortsUsers[0], AlcMiscUser(MR_SERIALPORT), sizeof(ae->ae_PortsUsers[0]));
  120.         stccpy(ae->ae_PortsUsers[1], AlcMiscUser(MR_SERIALBITS), sizeof(ae->ae_PortsUsers[1]));
  121.         stccpy(ae->ae_PortsUsers[2], AlcMiscUser(MR_PARALLELPORT), sizeof(ae->ae_PortsUsers[2]));
  122.         stccpy(ae->ae_PortsUsers[3], AlcMiscUser(MR_PARALLELBITS), sizeof(ae->ae_PortsUsers[3]));
  123.  
  124.         Permit();
  125.  
  126.         callback(ae, userData);
  127.  
  128.         tbFreeVecPooled(globalPool, ae);
  129.     }
  130. }
  131.  
  132. static void UpdateCallback( struct AllocationEntry *ae,
  133.                             void *userData )
  134. {
  135.     struct AllocationsCallbackUserData *ud = (struct AllocationsCallbackUserData *)userData;
  136.  
  137.     MySetContents(ud->ud_CIAAUsers, "%s\n%s\n%s\n%s\n%s", ae->ae_CIAAUsers[0], ae->ae_CIAAUsers[1], ae->ae_CIAAUsers[2], ae->ae_CIAAUsers[3], ae->ae_CIAAUsers[4]);
  138.     MySetContents(ud->ud_CIABUsers, "%s\n%s\n%s\n%s\n%s", ae->ae_CIABUsers[0], ae->ae_CIABUsers[1], ae->ae_CIABUsers[2], ae->ae_CIABUsers[3], ae->ae_CIABUsers[4]);
  139.     MySetContents(ud->ud_PortsUsers, "%s\n%s\n%s\n%s", ae->ae_PortsUsers[0], ae->ae_PortsUsers[1], ae->ae_PortsUsers[2], ae->ae_PortsUsers[3]);
  140. }
  141.  
  142. static void PrintCallback( struct AllocationEntry *ae,
  143.                            void *userData )
  144. {
  145.     PrintFOneLine((BPTR)userData, "\nCIA A:\n\n");
  146.     PrintFOneLine((BPTR)userData, "Timer A: %s\nTimer B: %s\n  Alarm: %s\n Serial: %s\n   Flag: %s\n", ae->ae_CIAAUsers[0], ae->ae_CIAAUsers[1], ae->ae_CIAAUsers[2], ae->ae_CIAAUsers[3], ae->ae_CIAAUsers[4]);
  147.  
  148.     PrintFOneLine((BPTR)userData, "\n\nCIA B:\n\n");
  149.     PrintFOneLine((BPTR)userData, "Timer A: %s\nTimer B: %s\n  Alarm: %s\n Serial: %s\n   Flag: %s\n", ae->ae_CIABUsers[0], ae->ae_CIABUsers[1], ae->ae_CIABUsers[2], ae->ae_CIABUsers[3], ae->ae_CIABUsers[4]);
  150.  
  151.     PrintFOneLine((BPTR)userData, "\n\nSerial & Parallel Ports:\n\n");
  152.     PrintFOneLine((BPTR)userData, "     Serial Port: %s\n  Serial Control: %s\n   Parallel Port: %s\nParallel Control: %s\n", ae->ae_PortsUsers[0], ae->ae_PortsUsers[1], ae->ae_PortsUsers[2], ae->ae_PortsUsers[3]);
  153. }
  154.  
  155. static void SendCallback( struct AllocationEntry *ae,
  156.                           void *userData )
  157. {
  158.     SendEncodedEntry((UBYTE *)ae, sizeof(struct AllocationEntry));
  159. }
  160.  
  161. static ULONG __saveds mNew( struct IClass *cl,
  162.                             Object *obj,
  163.                             struct opSet *msg )
  164. {
  165.     static UBYTE *allocationsPages[] = { "CIA", "Ports", NULL };
  166.     APTR pages, ciaaText, ciabText, portsText, updateButton, printButton, exitButton;
  167.  
  168.     if (obj = (Object *)DoSuperNew(cl, obj,
  169.         MUIA_HelpNode, AllocationsText,
  170.         MUIA_Window_ID, MakeID('A','L','L','C'),
  171.         WindowContents, VGroup,
  172.  
  173.             Child, pages = RegisterGroup(allocationsPages),
  174.  
  175.                 Child, HGroup,
  176.                     Child, HGroup,
  177.                         GroupFrameT("CIA A"),
  178.                         Child, HGroup,
  179.                             Child, MyLabel2(MUIX_R "Timer A:\nTimer B:\nAlarm:\nSerial:\nFlag:"),
  180.                             Child, ciaaText = MyTextObject(),
  181.                         End,
  182.                     End,
  183.                     Child, HGroup,
  184.                         GroupFrameT("CIA B"),
  185.                         Child, HGroup,
  186.                             Child, MyLabel2(MUIX_R "Timer A:\nTimer B:\nAlarm:\nSerial:\nFlag:"),
  187.                             Child, ciabText = MyTextObject(),
  188.                         End,
  189.                     End,
  190.                 End,
  191.  
  192.                 Child, HGroup,
  193.                     GroupFrameT("Ports"),
  194.                     Child, HGroup,
  195.                         Child, MyLabel2(MUIX_R "Serial Port:\nSerial Control:\nParallel Port:\nParallel Control:"),
  196.                         Child, portsText = MyTextObject(),
  197.                     End,
  198.                 End,
  199.             End,
  200.  
  201.             Child, MyVSpace(4),
  202.  
  203.             Child, HGroup, MUIA_Group_SameSize, TRUE,
  204.                 Child, updateButton = MakeButton(txtUpdate),
  205.                 Child, printButton  = MakeButton(txtPrint),
  206.                 Child, exitButton   = MakeButton(txtExit),
  207.             End,
  208.         End,
  209.         TAG_MORE, msg->ops_AttrList))
  210.     {
  211.         struct AllocationsWinData *awd = INST_DATA(cl, obj);
  212.         APTR parent;
  213.  
  214.         awd->awd_CIAAText = ciaaText;
  215.         awd->awd_CIABText = ciabText;
  216.         awd->awd_PortsText = portsText;
  217.  
  218.         parent = (APTR)GetTagData(MUIA_Window_ParentWindow, (ULONG)NULL, msg->ops_AttrList);
  219.  
  220.         set(obj, MUIA_Window_Title, MyGetWindowTitle("ALLOCATIONS", awd->awd_Title, sizeof(awd->awd_Title)));
  221.         set(obj, MUIA_Window_ActiveObject, pages);
  222.         set(pages, MUIA_CycleChain, TRUE);
  223.         MySetContents(awd->awd_CIAAText, "$%08lx\n$%08lx\n$%08lx\n$%08lx\n$%08lx", 0, 0, 0, 0, 0);
  224.         MySetContents(awd->awd_CIABText, "$%08lx\n$%08lx\n$%08lx\n$%08lx\n$%08lx", 0, 0, 0, 0, 0);
  225.         MySetContents(awd->awd_PortsText, "$%08lx\n$%08lx\n$%08lx\n$%08lx", 0, 0, 0, 0);
  226.  
  227.         DoMethod(parent,       MUIM_Window_AddChildWindow, obj);
  228.         DoMethod(obj,          MUIM_Notify, MUIA_Window_CloseRequest, TRUE,  MUIV_Notify_Application, 5, MUIM_Application_PushMethod, parent, 2, MUIM_Window_RemChildWindow, obj);
  229.         DoMethod(updateButton, MUIM_Notify, MUIA_Pressed,             FALSE, obj,                     1, MUIM_AllocationsWin_Update);
  230.         DoMethod(printButton,  MUIM_Notify, MUIA_Pressed,             FALSE, obj,                     1, MUIM_AllocationsWin_Print);
  231.         DoMethod(exitButton,   MUIM_Notify, MUIA_Pressed,             FALSE, obj,                     3, MUIM_Set, MUIA_Window_CloseRequest, TRUE);
  232.     }
  233.  
  234.     return (ULONG)obj;
  235. }
  236.  
  237. static ULONG __saveds mDispose( struct IClass *cl,
  238.                                 Object *obj,
  239.                                 struct opSet *msg )
  240. {
  241.     set(obj, MUIA_Window_Open, FALSE);
  242.  
  243.     return (DoSuperMethodA(cl, obj, msg));
  244. }
  245.  
  246. static ULONG __saveds mUpdate( struct IClass *cl,
  247.                                Object *obj,
  248.                                Msg msg )
  249. {
  250.     struct AllocationsWinData *awd = INST_DATA(cl, obj);
  251.     struct AllocationsCallbackUserData ud;
  252.  
  253.     ud.ud_CIAAUsers = awd->awd_CIAAText;
  254.     ud.ud_CIABUsers = awd->awd_CIABText;
  255.     ud.ud_PortsUsers = awd->awd_PortsText;
  256.  
  257.     if (clientstate) {
  258.         ReceiveList(UpdateCallback, &ud);
  259.     } else {
  260.         IterateList(UpdateCallback, &ud);
  261.     }
  262.  
  263.     return 0;
  264. }
  265.  
  266. static ULONG __saveds mPrint( struct IClass *cl,
  267.                               Object *obj,
  268.                               Msg msg )
  269. {
  270.     PrintAllocations(NULL);
  271.  
  272.     return 0;
  273. }
  274.  
  275. ULONG __asm __saveds AllocationsWinDispatcher( register __a0 struct IClass *cl,
  276.                                                register __a2 Object *obj,
  277.                                                register __a1 Msg msg )
  278. {
  279.     switch (msg->MethodID) {
  280.         case OM_NEW:                     return (mNew(cl, obj, (APTR)msg));
  281.         case OM_DISPOSE:                 return (mDispose(cl, obj, (APTR)msg));
  282.         case MUIM_AllocationsWin_Update: return (mUpdate(cl, obj, (APTR)msg));
  283.         case MUIM_AllocationsWin_Print:  return (mPrint(cl, obj, (APTR)msg));
  284.     }
  285.  
  286.     return (DoSuperMethodA(cl, obj, msg));
  287. }
  288.  
  289. void PrintAllocations( char *filename )
  290. {
  291.     BPTR handle;
  292.  
  293.     if (handle = HandlePrintStart(filename)) {
  294.         IterateList(PrintCallback, (void *)handle);
  295.     }
  296.  
  297.     HandlePrintStop();
  298. }
  299.  
  300. void SendAlcList( void )
  301. {
  302.     IterateList(SendCallback, NULL);
  303. }
  304.  
  305.